package com.booking.action;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.booking.bean.Users;
import com.booking.service.UserService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

@Controller
public class RegeditAction extends ActionSupport implements ModelDriven<Users>{

	@Autowired
	private Users user;
	
	@Autowired
	private UserService service;
	
	
	@Override
	public Users getModel() {
		return user;
	}
	
	public String Regedit() throws Exception{
		String regeditError;
		
		String regUser = service.saveUser(user);
		
		if(regUser == null || regUser.equals("")){
			//注册失败
			ActionContext.getContext().put("regeditError", "注册失败，用户名已存在");			
			return "input";
		}else{
			//注册成功
			ActionContext.getContext().put("regeditError", "注册成功");			
			return "success";
		}
	}
	

}
